def check(n, m):
    x = n# 检查n在m进制下是否是哈沙德数
    ans = 0
    while n > 0:
        ans += n % m
        n //= m
    return x % ans == 0

cnt = 0
i = 1
while 1:
    if check(i, 2) and check(i, 8) and check(i, 10) and check(i, 16):
        cnt += 1
    if cnt == 2023:
        print(i)
        break
    i += 1